//
//  YHStatusRetweetedView.swift
//  YHWeibo
//
//  Created by 昱含 on 16/5/25.
//  Copyright © 2016年 YuHan. All rights reserved.
//

import UIKit
import SnapKit

class YHStatusRetweetedView: UIView {
    
    var bottomCons: Constraint?
    
    var statusViewModel: YHStatusViewModel? {
        
        didSet{
            contentLabel.text = statusViewModel?.status?.retweeted_status?.text
//            pictureView.pictures = statusViewModel?.status?.retweeted_status?.pic_urls
            
            bottomCons?.uninstall()
            
            if let urls = statusViewModel?.status?.retweeted_status?.pic_urls where urls.count > 0{
                
                pictureView.pictures = urls
                self.snp_updateConstraints(closure: { (make) in
                    
                    self.bottomCons = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                    
                })
                
                pictureView.hidden = false
                
            }else{
                
                pictureView.pictures = nil
                
                pictureView.hidden = true
                
                self.snp_updateConstraints(closure: { (make) in
                    
                    self.bottomCons = make.bottom.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin).constraint
                    
                })
                
            }
        
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        backgroundColor = UIColor(white: 0.95, alpha: 1)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        addSubview(contentLabel)
        addSubview(pictureView)
        backgroundColor = UIColor(white: 0.90, alpha: 1)
        contentLabel.snp_makeConstraints { (make) in
            make.top.left.equalTo(self).offset(StatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentLabel.snp_left)
        }
        
        self.snp_makeConstraints { (make) in
            self.bottomCons = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
    }
    
    private lazy var contentLabel: UILabel = UILabel(title: "幸运四叶草", font: 14, textColor: UIColor.darkGrayColor(), alignment: .Left)
    
    private lazy var pictureView: YHStatusPictureView = YHStatusPictureView()

}
